//
//  DCFullTableViewCell.m
//  Driver
//
//  Created by 大橙子 on 2018/11/8.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCFullTableViewCell.h"

static const int kBaseCellHeight = 30;
@interface DCFullTableViewCell ()
@property (nonatomic,strong) DCImageAndTextLabel *suvLabel;
@property (nonatomic,strong) DCImageAndTextLabel *carLabel;
@end
@implementation DCFullTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCFullTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCFullTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = BackgroundColor;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    [self setUpBaseUIView];
    
    self.suvLabel = [[DCImageAndTextLabel alloc]init];
    self.suvLabel.imageView.image = IMAGENAME(@"SUV");
    self.suvLabel.textLabel.textColor = BlueColor;
    self.suvLabel.textLabel.text = @"x5";
    [self.secondView addSubview:self.suvLabel];
    
    self.carLabel = [[DCImageAndTextLabel alloc]init];
    self.carLabel.imageView.image = IMAGENAME(@"car");
    self.carLabel.textLabel.textColor = BlueColor;
    self.carLabel.textLabel.text = @"x6";
    [self.secondView addSubview:self.carLabel];
    
    [self.protectBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.driveMsgBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setUpLayoutSubViews];
    self.secondView.frame = CGRectMake(0, self.firstView.bottom+1, self.width, kBaseCellHeight*4);
//    self.carImageView.frame = CGRectMake(10, 15, self.secondView.height- 30, self.secondView.height - 30);
    self.carImageView.size = CGSizeMake(kBaseCellHeight*3-25, kBaseCellHeight*3-25);
    self.carImageView.y = (self.secondView.height - self.carImageView.height)/2;
    self.carImageView.x = 10;
    self.nameLabel.frame = CGRectMake(self.carImageView.right+5, 0, 100*WIDTHSCALE6, kBaseCellHeight);
    self.phoneLabel.frame = CGRectMake(self.nameLabel.x, self.nameLabel.bottom, 150*WIDTHSCALE6, kBaseCellHeight);
    self.locationLabel.frame = CGRectMake(self.nameLabel.x, self.phoneLabel.bottom, self.secondView.width - self.carImageView.width -15, kBaseCellHeight);
    self.carLabel.frame = CGRectMake(self.carImageView.right+20, self.locationLabel.bottom, (self.secondView.width - self.carImageView.width-30)/2, kBaseCellHeight);
    self.suvLabel.frame = CGRectMake(self.carLabel.right, self.carLabel.y, self.carLabel.width , kBaseCellHeight);
    
    self.thirdView.frame = CGRectMake(0, self.secondView.bottom+1, self.width, kBaseSubViewHeight);
    __weak typeof(self) weakself = self;
    [self.driveMsgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.thirdView.mas_right).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    
    [self.protectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.driveMsgBtn.mas_left).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
}
-(void)setModel:(DCCarManagerModel *)model
{
    _model = model;
    self.plateNumLabel.text = model.plateNum;
    self.stateLabel.text = model.state;
    self.nameLabel.textLabel.text = model.name;
    self.phoneLabel.textLabel.text = model.tel;
    self.locationLabel.textLabel.text = model.location;
    self.suvLabel.textLabel.text = [NSString stringWithFormat:@"x%@",model.suvNum];
    self.carLabel.textLabel.text = [NSString stringWithFormat:@"x%@",model.carNum];
}
-(void)btnDidClick:(UIButton *)button
{
    if (button.tag == 0) {
        DCLog(@"1-保养维护");
    }else if (button.tag == 1){
        DCLog(@"1-驾驶数据");
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
